package com.rest.demo.repository;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.Map;

@Repository
public class DyRcUserDaoJdbcTemplateImpl implements DyRcUserDao {
    @Autowired
    private NamedParameterJdbcTemplate jdbcTemplate;


//增加一条新数据
    @Override
    public int add(DyRcUser DyRcUser) {
        String sql = "insert into dysmt(name,age) " +"values(:name,:age)";//dysmt是表名
        Map<String, Object> param = new HashMap<>();
        param.put("name", DyRcUser.getName());
        param.put("age", DyRcUser.getAge());
        return (int) jdbcTemplate.update(sql, param);
    }

//

    public int Updata(DyRcUser DyRcUser) {
//        String sql = "insert into dysmt(name,age) " +"values(:name,:age)";//dysmt是表名
//        UPDATE 表名称 SET 列名称 = 新值 WHERE 列名称 = 某值

        String sql =" UPDATE dysmt SET name = "+"value(:name )"+" WHERE ID = 8";
//        String sql ="UPDATE dysmt"+"values(:name)"+"SET name = values(:name)"+" WHERE ID = 8";
        Map<String, Object> param = new HashMap<>();
        param.put("name", DyRcUser.getName());
        param.put("age", DyRcUser.getAge());
        return (int) jdbcTemplate.update(sql, param);
    }



//    update employee set lastName = ?,email=?,gender=?,d_id=? where id = ?",temp

//    public int update(@RequestParam("lastName")String lastName,@RequestParam("email")String email,
//                      @RequestParam("gender")String gender,@RequestParam("d_id")int d_id,@RequestParam("id")int id){
//        Object[] temp = new Object[5];
//        temp[0]= lastName;
//        temp[1]= email;
//        temp[2]= gender;
//        temp[3]= d_id;
//        temp[4]=id;
//        return jdbcTemplate.update("update employee set lastName = ?,email=?,gender=?,d_id=? where id = ?",temp);
//    }

}

